/* ----------------------------------------------------------------------
*
* Copyright (C) 2024 XiaoFei. All rights reserved.
*
* $file:		KangWei_AD9834.h
* $Date:        01-December-2024
* $Revision: 	V1
* $Project: 	XiaoFei BSP Library
* $Taobao:      https://item.taobao.com/item.htm?abbucket=17&id=42145466614
*
* -------------------------------------------------------------------- */

#ifndef __KangWei_AD9834_H
#define __KangWei_AD9834_H

#define AD9834_SYSTEM_COLCK             75000000UL
#define AD9834_RCC_FSY(x)				RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,(FunctionalState)x)
#define AD9834_RCC_SCK(x)				RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,(FunctionalState)x)
#define AD9834_RCC_SDA(x)				RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,(FunctionalState)x)
#define AD9834_RCC_RST(x)				RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,(FunctionalState)x)
#define AD9834_RCC_FS(x)				RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,(FunctionalState)x)
#define AD9834_RCC_PS(x)				RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,(FunctionalState)x)
#define AD9834_Port_FSY 				GPIOA
#define AD9834_Port_SCK 				GPIOA
#define AD9834_Port_SDA  			 	GPIOA
#define AD9834_Port_RST 				GPIOA
#define AD9834_Port_FS 				 	GPIOC
#define AD9834_Port_PS  				GPIOC
#define AD9834_Pin_FSY 				 	GPIO_Pin_0
#define AD9834_Pin_SCK 				 	GPIO_Pin_1
#define AD9834_Pin_SDA  			 	GPIO_Pin_2
#define AD9834_Pin_RST 				 	GPIO_Pin_3
#define AD9834_Pin_FS 				 	GPIO_Pin_0
#define AD9834_Pin_PS  					GPIO_Pin_1
#define AD9834_FSY(x)					GPIO_WriteBit(AD9834_Port_FSY,AD9834_Pin_FSY,(BitAction)(x))
#define AD9834_SCK(x)                   GPIO_WriteBit(AD9834_Port_SCK,AD9834_Pin_SCK,(BitAction)(x))
#define AD9834_SDA(x)                   GPIO_WriteBit(AD9834_Port_SDA,AD9834_Pin_SDA,(BitAction)(x))
#define AD9834_RST(x)                   GPIO_WriteBit(AD9834_Port_RST,AD9834_Pin_RST,(BitAction)(x))
#define AD9834_FS(x)                    GPIO_WriteBit(AD9834_Port_FS,AD9834_Pin_FS,(BitAction)(x))
#define AD9834_PS(x)                    GPIO_WriteBit(AD9834_Port_PS,AD9834_Pin_PS,(BitAction)(x))

#ifndef AD9834_FreqRegDef_def
#define AD9834_FreqRegDef_def
typedef enum
{
	AD9834_Freq0=0x4000 ,       /*!< The AD9834 freq reg 0 */
	AD9834_Freq1=0x8000         /*!< The AD9834 freq reg 1 */
}AD9834_FreqRegDef;
#endif

#ifndef AD9834_PhaseRegDef_def
#define AD9834_PhaseRegDef_def
typedef enum
{
	AD9834_Phase0=0xC000 ,      /*!< The AD9834 phase reg 0 */
	AD9834_Phase1=0xE000        /*!< The AD9834 phase reg 1 */
}AD9834_PhaseRegDef;
#endif

#ifndef AD9834_TypeDef_def
#define AD9834_TypeDef_def
typedef enum
{
	AD9834_Tri=0x2002 ,         /*!< The AD9834 output triangle wave */
	AD9834_Sin=0x2008 ,         /*!< The AD9834 output sine wave */
	AD9834_Squ=0x2028           /*!< The AD9834 output square wave */
}AD9834_TypeDef;
#endif


/* 
* @function: 	KangWei_AD9834_Init
*/
void KangWei_AD9834_Init(void);

/* 
* @function: 	KangWei_AD9834_SetFrequency
* @parameter:   [in] reg				A register used to write frequency words.
* @parameter:   [in] fre				The frequency you want to write.
* @parameter:   [in] type			    The type of waveform you want to generate.
*/
void KangWei_AD9834_SetFrequency(AD9834_FreqRegDef reg, float fre, AD9834_TypeDef type);

/* 
* @function: 	KangWei_AD9834_SetPhase
* @parameter:   [in] reg				A register used to write phase words.
* @parameter:   [in] val				The phase you want to write.
*/
void KangWei_AD9834_SetPhase(AD9834_PhaseRegDef reg, unsigned short int val);

#endif


